﻿using System;
using System.Collections.Generic;
using ControleRepresentante.Logic.Models;
using WebSite.Controllers;
using WebSite.ViewModels.Fields;

namespace WebSite.ViewModels.IndexViewModels
{
    public static class DetailsHolderIndexColumns
    {
        public static Guid Rua = new Guid("d9aed4e5-f933-41c8-ac1e-632fb8e36e9e");
        public static Guid Numero = new Guid("bd8b578e-ef83-4c39-9873-67b5e8fea133");
        public static Guid Complemento = new Guid("f9b28be4-ca66-4418-adb5-861292007b3a");
        public static Guid Bairro = new Guid("f48d5c12-d82e-41ae-8682-b02164db39ee");
        public static Guid CEP = new Guid("028a15dc-ce7b-4336-88ea-47ae173cb3f2");
        public static Guid Cidade = new Guid("1eb9f3a8-e5e0-445b-a1f4-976adaea0e11");
        public static Guid Estado = new Guid("e4729c9b-7f7b-4639-bd48-4c1d98b1feaa");

        public static Guid Telefone = new Guid("8fefe7bf-a8d7-4edd-a22c-488eb1045674");
        public static Guid Fax = new Guid("1c71965f-12d0-4505-a40f-0f369c8abf58");
        public static Guid Email = new Guid("0c73e053-9da5-458e-8d63-20ea521f3e9c");
        public static Guid Celular = new Guid("2ab590e2-b804-4e00-acb8-02c1952fc552");
    }

    public abstract class DetailsHolderIndexViewModel<TModel> : AttributeHolderIndexViewModel<TModel>, IDetailsHolderIndexViewModel
        where TModel : DetailsHolder
    {
        protected DetailsHolderIndexViewModel(string title)
            : base(title)
        {
        }

        public string CidadeBuscaValue { get; set; }
        public string BairroBuscaValue { get; set; }

        protected override IEnumerable<IField> GetSearchFields()
        {
            List<IField> result = new List<IField>
            {
                new AutoCompleteField("Cidade", "cidade", CidadeBuscaValue, "SearchCidade", ControllerName),
                new AutoCompleteField("Bairro", "bairro", BairroBuscaValue, "SearchBairro", ControllerName)
            };

            result.AddRange(base.GetSearchFields());
            return result;
        }

        protected override void RegisterColumns(IndexColumnDefinitionsCollectionWrapper<TModel> indexColumnDefinitionsCollectionWrapper)
        {
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Rua, x => x.EnderecoRua);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Numero, x => x.EnderecoNumero);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Complemento, x => x.EnderecoComplemento);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Bairro, x => x.EnderecoBairro);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.CEP, x => x.EnderecoCEP);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Cidade, x => x.EnderecoCidade);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Estado, x => x.EnderecoEstado);

            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Telefone, x => x.ContatoTelefone);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Fax, x => x.ContatoFax);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Email, x => x.ContatoEmail);
            indexColumnDefinitionsCollectionWrapper.Register(DetailsHolderIndexColumns.Celular, x => x.ContatoCelular);

            base.RegisterColumns(indexColumnDefinitionsCollectionWrapper);
        }
    }
}